<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * By：		o熊小猫o
 * Email：	show1990@foxmail.com
 */
class Model extends CI_Model {
	function __construct()
	{}
	
	//SELECT * FROM 表1 LEFT JOIN 表2 ON 表1.id=表2.cid;
	function news($table1,$table2,$array)
	{
		$this->db->select('*');
		$this->db->from("$table1");
		$this->db->join("$table2", "$table1.sid = $table2.sid",'left');
		$this->db->where($array);
		$query = $this->db->get();
		return $query->result();
	}

	function login($table,$array)
	{
		$this->db->where($array);
		$query = $this->db->get($table);
		return $query->num_rows();
	}

	function get($table,$order)
	{
		$query = $this->db->get($table);
		$this->db->order_by("id", "$order");
		return $query->result();
	}
	function select($table,$data)
	{
		$this->db->where($data);
		$query = $this->db->get($table);
		return $query->result();
	}
	
	function news_select($table,$data,$order)
	{
		$this->db->where($data);
		$this->db->order_by("id", "$order");
		$query = $this->db->get($table);
		return $query->result();
	}
	
	//page
	function select_num_rows($table,$data)
	{
		$this->db->where($data);
		$query = $this->db->get($table);
		return  $query->num_rows();
	}
	
	function get_page($table,$offset,$num,$order,$data)	
	{
		$this->db->where($data);
		$this->db->limit($offset,$num);
		$this->db->order_by("id", "$order");
		$query = $this->db->get($table);
		return $query->result();
	}

	function prev($id,$table)
	{
		$query = $this->db->query("SELECT * FROM $table WHERE id < $id ORDER BY id DESC LIMIT 1 ");
		return $query->result();
	}

	function next($id,$table)
	{
		$query = $this->db->query("SELECT * FROM $table WHERE id > $id ORDER BY id ASC LIMIT 1 ");
		return $query->result();
	}

	function insert($table, $data)
	{
		$this->db->insert($table, $data);
		return $this->db->affected_rows();
	}

	function update($table,$data,$id)
	{
		$this->db->where('id', $id);
		$this->db->update($table , $data);
		return  $this->db->affected_rows();
	}

	function delete($table,$id)
	{
		$this->db->where('id', $id);
		$this->db->delete($table);
		return $this->db->affected_rows();
	}

}

/* End of file model.php */
/* Location: ./application/models/model.php */